package com.jd.tank.abstractfactory.rectangle;

import com.jd.tank.Direction;
import com.jd.tank.Group;
import com.jd.tank.TankFrame;
import com.jd.tank.abstractfactory.BaseBullet;
import com.jd.tank.abstractfactory.BaseExplode;
import com.jd.tank.abstractfactory.BaseGameFactory;
import com.jd.tank.abstractfactory.BaseTank;

/**
 * @program: MyTank
 * @description:
 * @author: 王术平
 * @create: 2021-01-13 19:30
 **/
public class RectangleFactory extends BaseGameFactory {

    private static volatile RectangleFactory rectangleFactory;

    private RectangleFactory(){}

    public static RectangleFactory getRectangleFactory(){
        if (rectangleFactory == null) {
            synchronized (RectangleFactory.class) {
                if (rectangleFactory == null) {
                    rectangleFactory=new RectangleFactory();
                }
            }
        }
        return rectangleFactory;
    }


    /**
     * 创建坦克
     *
     * @param x
     * @param y
     * @param dir
     * @param group
     * @param tf
     * @param moving
     */
    @Override
    public BaseTank createTank(int x, int y, Direction dir, Group group, TankFrame tf, boolean moving) {
        return new SquareTank(x, y, dir, group, tf, moving);
    }

    /**
     * 创建子弹
     *
     * @param x
     * @param y
     * @param dir
     * @param group
     * @param tf
     */
    @Override
    public BaseBullet createBullet(int x, int y, Direction dir, Group group, TankFrame tf) {
        return new SquareBullet(x, y, dir, group, tf);
    }

    /**
     * 创建爆炸特效
     *
     * @param x
     * @param y
     */
    @Override
    public BaseExplode createExplode(int x, int y) {
        return new SquareExplode(x,y);
    }
}
